<template>
  <div id="testlist">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/jyzd' }">干部队伍状况调研</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
        <el-form :inline="true" :model="filters">
          <div>
            <el-form-item label="年度">
              <el-select v-model="filters.theyear" placeholder="请选择" style="width:100px">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="(item, index) in yearlist" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="单位编码">
              <el-input v-model="filters.code" placeholder="单位编码" @keyup.enter.native="searchPrj" style="width:100px"></el-input>
            </el-form-item>
            <el-form-item label="单位名称">
              <el-input v-model="filters.inname" placeholder="关键字" @keyup.enter.native="searchPrj"></el-input>
            </el-form-item>
            <el-form-item label="状态">
              <el-select v-model="filters.status" placeholder="请选择" style="width:100px">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="(item, index) in statusdic" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="searchTest" icon="el-icon-search">查询</el-button>
            </el-form-item>
            <el-form-item>
              <el-tooltip content="导入外网初始化数据包" placement="top">
                <router-link :to="{ path: '/jyzd/import'}" exact>
                  <el-button type="success" icon="el-icon-upload2">导入</el-button>
                </router-link>
              </el-tooltip>
            </el-form-item>
            <el-form-item>
              <!-- <el-tooltip content="年度考核分析表" placement="top"> -->
                <!-- <router-link :to="{ path: '/jyzd/export'}" exact>
                  <el-button type="primary" icon="el-icon-download">分析表</el-button>
                </router-link> -->
              <!-- </el-tooltip> -->
            </el-form-item>
          </div>
        </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <h1>测评列表</h1>
      <el-table :data="prjs" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border>
        <el-table-column type="index" label=" " width="50" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column prop="theYear" label="年度" width="70">
        </el-table-column>
        <el-table-column prop="code" label="单位编码" width="80">
        </el-table-column>
        <el-table-column prop="inname" label="单位名称" width="300">
        </el-table-column>
        <el-table-column label="创建时间" width="170">
          <template slot-scope="scope">
            {{dateFtt("yyyy-MM-dd hh:mm:ss",scope.row.createTime)}}
          </template>
        </el-table-column>
        <el-table-column label="状态" width="150">
          <template slot-scope="scope">
            {{statusid2name(scope.row.status)}}
          </template>
        </el-table-column>
        <el-table-column label="投票开始时间" width="170">
          <template slot-scope="scope">
            {{dateFtt("yyyy-MM-dd hh:mm:ss",scope.row.startTime)}}
          </template>
        </el-table-column>
        <el-table-column label="投票结束时间" width="170">
          <template slot-scope="scope">
            {{dateFtt("yyyy-MM-dd hh:mm:ss",scope.row.endTime)}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="small" @click="editPrj(scope.row.id)" type="text" icon="el-icon-edit" v-if="scope.row.status===1">起草</el-button>
            <el-button size="small" @click="exportPrj(scope.row.id)" type="text" icon="el-icon-s-claim" v-if="scope.row.status===1" :loading="myloading">结束起草</el-button>
            <el-button size="small" @click="detailPrj(scope.row.id)" type="text" icon="el-icon-search" v-if="scope.row.status!==1">查看详情</el-button>
            <el-button size="small" @click="delPrj(scope.row.id)" type="text" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    <div class="block">
      <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    </div>
    </section>
  </div>
</template>

<script>
import getunits from '@/js/common.js'
export default {
  data () {
    return {
      testAddFormVisible: false,
      testAddFormLoading: false,
      testAddForm: {
        UserName: '',
        PassWord: '',
        TrueName: '',
        UnitName: '',
        Enable: '停用'
      },
      filters: {
        status: '',
        code: '',
        theyear: ''
      },
      discs: {},
      prjs: [],
      total: 0,
      pageNum: 1,
      pageSize: 20,
      listLoading: false,
      totalnum: 0,
      Isace: true,
      Sortkey: '',
      changeSizeFlag: false,
      tableHeight: 100,
      statusdic: [],
      yearlist: [],
      myloading: false
    }
  },
  methods: {
    detailPrj (id) {
      // window.open(this.$http.defaults.baseURL + 'project/detail/' + id)
      this.$router.push('/jyzd/detail/' + id)
    },
    exportPrj (id) {
      var _this = this
      this.$confirm('确定结束起草?', '提示', {
        type: 'success'
      }).then(() => {
        this.myloading = true
        this.$http.post(`/api/prj/finishqicao/` + id).then(function (response) {
          if (response.data.success === true) {
            _this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            console.log('操作失败:' + response.data.message)
            _this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
          _this.myloading = false
          _this.getPrj()
        })
      })
    },
    editPrj: function (id) {
      console.log('editid:' + id)
      this.$router.push({path: '/jyzd/edit/' + id})
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getPrj()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getPrj()
      }
    },
    querySearch (queryString, cb) {
      return getunits(this, queryString, cb)
    },
    // 查询
    searchTest () {
      this.pageNum = 1
      this.getPrj()
    },
    // 排序
    sortChange: function (column, prop, order) {
      this.Sortkey = column.prop
      if (column.order === 'ascending') {
        this.Isace = true
      } else {
        this.Isace = false
      }
      this.getPrj()
    },
    getPrj () {
      let para = {
        code: this.filters.code,
        inname: this.filters.inname,
        status: this.filters.status,
        theyear: this.filters.theyear,
        innametype: 'JiaoYuZhengDun',
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      var _this = this
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(`/api/prj/search`, para)
        .then(function (response) {
          _this.listLoading = false
          _this.prjs = response.data.list
          _this.totalnum = response.data.total
          _this.changeSizeFlag = false
        })
        .catch(function (error) {
          _this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    delPrj (id) {
      var _this = this
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'error'
      }).then(() => {
        this.$http.post(`/api/prj/remove/` + id).then(function (response) {
          if (response.data.success === true) {
            _this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            console.log('删除失败:' + response.data.message)
            _this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
          _this.getPrj()
        })
      }).catch(() => {
      })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 292
      })
    },
    getDics () {
      var _this = this
      this.$http
        .get(`/api/prj/syqdic`)
        .then(function (response) {
          _this.statusdic = response.data.statusdic
          _this.yearlist = response.data.yeardic
        })
        .catch(function (error) {
          console.log(error)
          _this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    statusid2name (id) {
      for (let i = 0; i < this.statusdic.length; i++) {
        if (this.statusdic[i].id === id) {
          return this.statusdic[i].name
        }
      }
    }
  },
  mounted () {
    this.getPrj()
    this.getDics()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  .el-table--border th, .el-table--border td {
    border-right: 1px solid #95B8E7;
  }
  .el-table th.is-leaf, .el-table td {
    border-bottom: 1px solid #95B8E7;
  }

</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
